#include <avr/io.h>
#include <util/delay.h>
#include <stdio.h>

#ifndef F_CPU
#define F_CPU 16000000
#endif
//set desired baud rate
#define BAUDRATE 9600
//calculate UBRR value
#define UBRRVAL ((F_CPU/(BAUDRATE*16UL))-1)

char n,		//number
c;		//current state of display

void SendChar(char Tegn)
{
  // Wait for transmitter register empty (ready for new character)
  while ( !UDRE )
  {}
  // Then send the character
  UDR = Tegn;
}

int main(void)
{
	//Set baud rate
	UBRRL=UBRRVAL;		//low byte
	UBRRH=(UBRRVAL>>8);	//high byte

	//Set data frame format: asynchronous mode,no parity, 1 stop bit, 8 bit size
	UCSRC=(1<<URSEL)|(0<<UMSEL)|(0<<UPM1)|(0<<UPM0)|(0<<USBS)|(0<<UCSZ2)|(1<<UCSZ1)|(1<<UCSZ0);

	//Enable Transmitter and Receiver
	UCSRB=(1<<RXEN)|(1<<TXEN);
	DDRA=0x00;	//all A port pins as input
	PORTA=0xFF;	//Enable internal Pull-Up resistors
	DDRB=0xFF;	//All B port pins as output

	while(1)
	{
		SendChar('J');
		/*
		c=1; 	//start with first LED
		while(PINA==0xFF) //wait for button to be pressed
		{
			if (c==0) c=1;	//if light passed all leds start over
			PORTB=~c;		//LED on
			_delay_ms(100);//short delay
			n++;			//increase number value
			c=c<<1;			//shift li9ghted LED
		}
		//wait for empty transmit buffer
		while (!(UCSRA&(1<<UDRE))){};
		UDR=n;		//send number to USART
		PORTB=~n;				//and dislpaly number with led(binary)
		_delay_ms(200);	//long delay
		PORTB=0xFF;			//All LEDs OFF
		*/
	}
	return 0;
}
